package com.ruoyi.ax.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;

import com.ruoyi.ax.domain.*;
import com.ruoyi.ax.mapper.AxAuthorizationSellMapper;
import com.ruoyi.ax.mapper.AxUserMapper;
import com.ruoyi.ax.service.*;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.MoneyTypeEnum;
import com.ruoyi.common.enums.changeSouceType;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysUserService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ax.mapper.AxOrderMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Service
public class AxOrderServiceImpl implements IAxOrderService 
{
    @Autowired
    private AxOrderMapper axOrderMapper;

    @Autowired
    private IAxRoundService iAxRoundService;

    @Autowired
    private ISysUserService userService;


    @Autowired
    private AxUserMapper axUserMapper;

    @Autowired
    private AxAuthorizationSellMapper axAuthorizationSellMapper;

    @Autowired
    private IAxAccountChangeRecordService axAccountChangeRecordService;

    @Autowired
    private IAxGoodService iAxGoodService;
    @Autowired
    private  IAxMemberLevelService iAxMemberLevelService;

    @Autowired
    private IAxDictDataService axDictDataService;


    /**
     * 查询订单
     * 
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public AxOrder selectAxOrderById(Long id)
    {
        AxOrder axOrder = axOrderMapper.selectAxOrderById(id);
        axOrder.setAxGood( iAxGoodService.selectAxGoodById(axOrder.getGoodId()));
        return axOrder;
    }

    /**
     * 查询订单列表
     * 
     * @param axOrder 订单
     * @return 订单
     */
    @Override
    public List<AxOrder> selectAxOrderList(AxOrder axOrder)
    {
        List<AxOrder> list= axOrderMapper.selectAxOrderList(axOrder);
        for(AxOrder axOrder1:list){
            AxGood axGood = iAxGoodService.selectAxGoodById(axOrder1.getGoodId());
          //  AxRound axRound=   iAxRoundService.selectAxRoundById(axOrder1.getRoundId());
           //  Double sellPrice  =   ((Double.valueOf(axGood.getDayIncreaseRate())/100)+1)*(Double.valueOf(axOrder1.getPrice().toString()));
           // axRound.setTodayPrice(new BigDecimal(sellPrice.toString()).setScale(2, RoundingMode.HALF_UP).toString());
            Double sellPrice  =  (Double.valueOf(axOrder1.getPrice().toString()));
            axGood.setTodayPrice(new BigDecimal(sellPrice.toString()).setScale(2, RoundingMode.HALF_UP).toString());
            axOrder1.setAxGood(axGood);
            axOrder1.setSysUser(userService.selectUserById(axOrder1.getSysUserId()));
          //  axOrder1.setPrice(new BigDecimal(sellPrice).setScale(2, RoundingMode.HALF_UP));

        }
        return list;
    }


    @Override
    public List<AxOrder> selectMyAxOrderList(AxOrder axOrder){
        List<AxOrder> list= axOrderMapper.selectAxOrderList(axOrder);
        for(AxOrder axOrder1:list){
            axOrder1.setAxGood(iAxGoodService.selectAxGoodById(axOrder1.getGoodId()));
        }
        return list;
    }

    /**
     * 新增订单
     * 
     * @param axOrder 订单
     * @return 结果
     */
    @Override
    public int insertAxOrder(AxOrder axOrder)
    {
        axOrder.setCreateTime(DateUtils.getNowDate());
        return axOrderMapper.insertAxOrder(axOrder);
    }



    /**
     * B平台购买商品
     * @param axOrder
     * @return
     */
    @Override
    @Transactional
    public int  buyPbGood(AxOrder axOrder){
        Long sysUserId= SecurityUtils.getUserId();
        axOrder.setPlatform("B");
        AxGood axGood=iAxGoodService.selectAxGoodById(axOrder.getGoodId());
        BigDecimal  totalFee = new BigDecimal(axGood.getTodayPrice()).multiply(new BigDecimal(axOrder.getTotalNum()));
        axOrder.setOrderNum(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS,new Date())+getMillseconds());
        axOrder.setSysUserId(sysUserId);
        axOrder.setTotalFee(totalFee.setScale(2,RoundingMode.HALF_UP));
        axOrder.setPrice(new BigDecimal(axGood.getTodayPrice()).setScale(2,RoundingMode.HALF_UP));
        axOrderMapper.insertAxOrder(axOrder);

        if(MoneyTypeEnum.余额.getCode()==axOrder.getMoneyType()){

            SysUser sysUser = userService.selectUserById(sysUserId);
            if(new BigDecimal(sysUser.getRechargeAmount()).compareTo(totalFee)<0){
                throw  new GlobalException("抱歉，余额不足");
            }
            BigDecimal rechargeAmount= new BigDecimal(sysUser.getRechargeAmount());
            //减去消费券总量
            sysUser.setRechargeAmount((rechargeAmount.subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 增加可提现券总量
           // sysUser.setAbleCashIncome(totalFee.add(new BigDecimal(sysUser.getAbleCashIncome())).setScale(2, RoundingMode.HALF_UP).toString());
            userService.updateUser(sysUser);
            // 增加变动明细；
            return  this.adAccountChangeRecord(axOrder,"-"+totalFee,sysUserId
                    ,"","",changeSouceType.B商品余额购买.getCode(),changeSouceType.B商品余额购买.name());
        }else if(MoneyTypeEnum.提货券.getCode()==axOrder.getMoneyType()) {
            SysUser sysUser = userService.selectUserById(sysUserId);
            if(new BigDecimal(sysUser.getAbleConsumeTotalIncome()).compareTo(totalFee)<0){
                throw  new GlobalException("抱歉，余额不足");
            }
            BigDecimal ableConsumeTotalIncome= new BigDecimal(sysUser.getAbleConsumeTotalIncome());
            //减去消费券总量
            sysUser.setAbleConsumeTotalIncome((ableConsumeTotalIncome.subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 减去提现券；
            sysUser.setTotalIncome( (new BigDecimal(sysUser.getTotalIncome()).subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 增加可提现券总量,即可提现总额
            sysUser.setAbleCashIncome(totalFee.add(new BigDecimal(sysUser.getAbleCashIncome())).setScale(2, RoundingMode.HALF_UP).toString());
            userService.updateUser(sysUser);
            // 增加变动明细；
            return  this.adAccountChangeRecord(axOrder,"-"+totalFee,sysUserId
                    ,"","",changeSouceType.拍品券.getCode(),changeSouceType.拍品券.name());

        }else{
            throw  new GlobalException("不支持该付款方式");
        }

    }

    //B平台购买津贴商品
    @Override
    @Transactional
    public int  buyAllowanceGood(AxOrder axOrder){

        Long sysUserId= SecurityUtils.getUserId();
        axOrder.setPlatform("B");
        AxGood axGood=iAxGoodService.selectAxGoodById(axOrder.getGoodId());
        BigDecimal  totalFee = new BigDecimal(axGood.getTodayPrice()).multiply(new BigDecimal(axOrder.getTotalNum()));
        axOrder.setOrderNum(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS,new Date())+getMillseconds());
        axOrder.setSysUserId(sysUserId);
        axOrder.setTotalFee(totalFee.setScale(2,RoundingMode.HALF_UP));
        axOrder.setPrice(new BigDecimal(axGood.getTodayPrice()).setScale(2,RoundingMode.HALF_UP));
        axOrderMapper.insertAxOrder(axOrder);
        if(MoneyTypeEnum.津贴券.getCode()==axOrder.getMoneyType()){
            SysUser sysUser = userService.selectUserById(sysUserId);
            if(new BigDecimal(sysUser.getIndirectIncome()).compareTo(totalFee)<0){
                throw  new GlobalException("抱歉，余额不足");
            }
            BigDecimal indirectIncome= new BigDecimal(sysUser.getIndirectIncome());
            //减去消费券总量
            sysUser.setIndirectIncome((indirectIncome.subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 减去提现券；
            sysUser.setTotalIncome( (new BigDecimal(sysUser.getTotalIncome()).subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 增加可提现券总量
            sysUser.setIndirectAbleCashIncome(totalFee.add(new BigDecimal(sysUser.getIndirectAbleCashIncome())).setScale(2, RoundingMode.HALF_UP).toString());
            userService.updateUser(sysUser);
            // 增加变动明细；
            return  this.adAccountChangeRecord(axOrder,"-"+totalFee,sysUserId
                    ,"","",changeSouceType.津贴券.getCode(),changeSouceType.津贴券.name());
        }else if(MoneyTypeEnum.余额.getCode()==axOrder.getMoneyType()){
            SysUser sysUser = userService.selectUserById(sysUserId);
            if(new BigDecimal(sysUser.getRechargeAmount()).compareTo(totalFee)<0){
                throw  new GlobalException("抱歉，余额不足");
            }
            BigDecimal rechargeAmount= new BigDecimal(sysUser.getRechargeAmount());
            //减去消费券总量
            sysUser.setRechargeAmount((rechargeAmount.subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
            // 增加可提现券总量
            // sysUser.setAbleCashIncome(totalFee.add(new BigDecimal(sysUser.getAbleCashIncome())).setScale(2, RoundingMode.HALF_UP).toString());
            userService.updateUser(sysUser);
            // 增加变动明细；
            return  this.adAccountChangeRecord(axOrder,"-"+totalFee,sysUserId
                    ,"","",changeSouceType.津贴商品余额购买.getCode(),changeSouceType.津贴商品余额购买.name());

        }else{
            throw  new GlobalException("不支持该付款方式");
        }

    }


    @Override
    @Transactional
    public int buyGood(AxOrder axOrder) {
        AxRound axRound= iAxRoundService.selectAxRoundById(axOrder.getRoundId());
        AxGood axGood=iAxGoodService.selectAxGoodById(axOrder.getGoodId());
        Long sysUserId= SecurityUtils.getUserId();
         // 判断是否在抢购时间内
          //年月日在
         Date roundBeginTime=  DateUtils.parseDate( axGood.getBeginYmd()+" "+axRound.getDayBeginTime()) ;
         Date roundEndTime=   DateUtils.parseDate( axGood.getEndYmd()+" "+axRound.getDayEndTime());
         // 时分秒也在
         Date roundTodayBeginTime=  DateUtils.parseDate( DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date())+" "+axRound.getDayBeginTime()) ;
         Date roundTodayEndTime=   DateUtils.parseDate( DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date())+" "+axRound.getDayEndTime());
        if((roundBeginTime.getTime()<System.currentTimeMillis() && roundEndTime.getTime() >System.currentTimeMillis())
          && (roundTodayBeginTime.getTime()<System.currentTimeMillis() && roundTodayEndTime.getTime() >System.currentTimeMillis()))
        {

        }else{
            throw  new GlobalException("抱歉，不在抢购时间范围内");
        }

        // 剩余库存
        int remainCount = Integer.parseInt(axGood.getTodayGoodCount()) - Integer.parseInt(axGood.getTodaySellGoodCount());
        if( remainCount  >= axOrder.getTotalNum()){
            axGood.setTodaySellGoodCount(Integer.parseInt(axGood.getTodaySellGoodCount())+axOrder.getTotalNum()+"");
            axGood.setGoodCounts(axGood.getGoodCounts()+axOrder.getTotalNum());
          ///  iAxRoundService.updateAxRound(axGood);
            iAxGoodService.updateAxGood(axGood);
          }else{
            throw  new GlobalException("抱歉，商品已抢购完，没有了");
        }
        //插入订单
        BigDecimal  totalFee = new BigDecimal(axGood.getTodayPrice()).multiply(new BigDecimal(axOrder.getTotalNum()));
        axOrder.setOrderNum(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS,new Date())+getMillseconds());
        axOrder.setOrderType(1l);
        axOrder.setSysUserId(sysUserId);
        axOrder.setTotalFee(totalFee.setScale(2,RoundingMode.HALF_UP));
        axOrder.setPrice(new BigDecimal(axGood.getTodayPrice()).setScale(2,RoundingMode.HALF_UP));
        axOrderMapper.insertAxOrder(axOrder);
        // 扣将用户余额
        SysUser sysUser = userService.selectUserById(sysUserId);
        if(new BigDecimal(sysUser.getRechargeAmount()).compareTo(totalFee)<0){
            throw  new GlobalException("抱歉，余额不足");
        }
       // BigDecimal remainRewardPoints= new BigDecimal(sysUser.getRemainRewardPoints()).subtract(totalFee);
       // sysUser.setRemainRewardPoints(remainRewardPoints.toString());

        BigDecimal remainRecharge= new BigDecimal(sysUser.getRechargeAmount());
        sysUser.setRechargeAmount((remainRecharge.subtract(totalFee)).setScale(2, RoundingMode.HALF_UP).toString());
        userService.updateUser(sysUser);
        //增加购买明细
        return   this.adAccountChangeRecord(axOrder,"-"+totalFee,sysUserId
                ,"","",changeSouceType.购买.getCode(),changeSouceType.购买.name());

        // 增加客户积分明细
//        AxAccountChangeRecord axAccountChangeRecord=new AxAccountChangeRecord();
//        axAccountChangeRecord.setOrderNumber(axOrder.getOrderNum());
//        axAccountChangeRecord.setUnitPrice(axOrder.getPrice()+"");
//        axAccountChangeRecord.setShopNumber(axOrder.getTotalNum());
//        axAccountChangeRecord.setOrderId(axOrder.getId()+"");
//        axAccountChangeRecord.setChangeSource(changeSouceType.购买.getCode());
//        axAccountChangeRecord.setChangeAmount("-"+totalFee);
//        axAccountChangeRecord.setChangeSourceName(changeSouceType.购买.name());
//        axAccountChangeRecord.setSysuserId(sysUserId);
//        axAccountChangeRecord.setIncome(String.format("%.2f",userIncomeRate));
//        axAccountChangeRecord.setIncomeRate(axMemberLevel.getIncomeRate());
//        return axAccountChangeRecordService.insertAxAccountChangeRecord(axAccountChangeRecord);
    }

    /**
     *
     * @param axOrder
     * @param totalFee 总收益
     * @param sysUserId  变动人id
     * @param userIncome 收益
     * @param incomeRate  收益率
     * @return
     */
    public int  adAccountChangeRecord(AxOrder axOrder, String totalFee, long sysUserId, String userIncome, String incomeRate,
                                      String changeSource , String  changeSourceName) {
        AxAccountChangeRecord axAccountChangeRecord=new AxAccountChangeRecord();
        axAccountChangeRecord.setOrderNumber(axOrder.getOrderNum());
        axAccountChangeRecord.setUnitPrice(axOrder.getPrice()+"");
        axAccountChangeRecord.setShopNumber(axOrder.getTotalNum());
        axAccountChangeRecord.setOrderId(axOrder.getId()+"");
        axAccountChangeRecord.setChangeSource(changeSource);
        axAccountChangeRecord.setGoodId(axOrder.getGoodId());
        axAccountChangeRecord.setChangeAmount(totalFee);
        axAccountChangeRecord.setChangeSourceName(changeSourceName);
        axAccountChangeRecord.setSysuserId(sysUserId);
        axAccountChangeRecord.setIncome(userIncome);
        axAccountChangeRecord.setIncomeRate(incomeRate);
        return axAccountChangeRecordService.insertAxAccountChangeRecord(axAccountChangeRecord);
    }

    @Override
    @Transactional
    public int sellGood( AxAuthorizationSell axAuthorizationSell) {
        AxOrder axOrder= axOrderMapper.selectAxOrderById(axAuthorizationSell.getOrderId());
        if(axOrder.getOrderType()==2){
            throw  new GlobalException("该商品已经出售");
        }
        axOrder.setOrderType(2l);
        axOrderMapper.updateAxOrder(axOrder);

        AxRound axRound= iAxRoundService.selectAxRoundById(axOrder.getRoundId());
        AxGood axGood=iAxGoodService.selectAxGoodById(axOrder.getGoodId());
        Long sysUserId= SecurityUtils.getUserId();
        // 判断是否在抢购时间内
        //年月日在
        Date roundBeginTime=  DateUtils.parseDate( axGood.getBeginYmd()+" "+axRound.getAuthorizationSellTime()) ;
        Date roundEndTime=   DateUtils.parseDate( axGood.getEndYmd()+" "+axRound.getAuthorizationSellTimeEnd());

        Date roundTodayBeginTime=  DateUtils.parseDate( DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date())+" "+axRound.getAuthorizationSellTime()) ;
        Date roundTodayEndTime=   DateUtils.parseDate( DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date())+" "+axRound.getAuthorizationSellTimeEnd());

        // 时分秒也在
        if((roundBeginTime.getTime()<System.currentTimeMillis() && roundEndTime.getTime() >System.currentTimeMillis())
                && (roundTodayBeginTime.getTime()<System.currentTimeMillis() && roundTodayEndTime.getTime() >System.currentTimeMillis()))
        {

        }else{
            throw  new GlobalException("抱歉，不在委拍时间范围内");
        }


        //插入委派记录

        //AxAuthorizationSell axAuthorizationSell=new AxAuthorizationSell();
       // axAuthorizationSell.setOrderId(axOrder.getId());
        // 按比例增长后的单价
        //Double sellPrice  =   ((Double.valueOf(axGood.getDayIncreaseRate())/100)+1)*(Double.valueOf(axOrder.getPrice().toString()));
        // 卖出
        Double sellPrice  =Double.valueOf(axOrder.getPrice().toString());
        axAuthorizationSell.setSellPrice(String.format("%.2f", sellPrice));
        axAuthorizationSell.setSellNumber(axOrder.getTotalNum());
       // axAuthorizationSell.setSellIncreateRate(axGood.getDayIncreaseRate());
        axAuthorizationSell.setWpOrderNumber(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS,new Date())+getMillseconds());
        axAuthorizationSell.setSysUserId(sysUserId);
        axAuthorizationSell.setGoodId(axOrder.getGoodId());

        // 更新订单状态
//        axOrder.setOrderType(2l);
//        axOrderMapper.updateAxOrder(axOrder);

       //  BigDecimal  totalFee =new BigDecimal(sellPrice).multiply(new BigDecimal(axOrder.getTotalNum()));
        Double   totalFee = sellPrice * (Double.valueOf(axOrder.getTotalNum()));
        // 增加余额
        SysUser axUser = userService.selectUserById(sysUserId);
        //Double remainRewardPoints= Double.valueOf(axUser.getRemainRewardPoints())+(totalFee);
        //axUser.setRemainRewardPoints((String.format("%.2f", remainRewardPoints)));
        Double remainRechargeAmout= Double.valueOf(axUser.getRechargeAmount())+(totalFee);
        axUser.setRechargeAmount((String.format("%.2f", remainRechargeAmout)));
        /////////////直接增加收益
        AxMemberLevel axMemberLevel= iAxMemberLevelService.selectAxMemberLevelById(axUser.getMemberId());



        // 增加间接收益
        if(StringUtils.isNotEmpty(axUser.getInvitationCodeBy())){
           // AxDictData axDictData=  axDictDataService.selectAxDictDataById(1l);
            SysUser sysUserParam = userService.selectUserByInvitationCode(axUser.getInvitationCodeBy());
            AxMemberLevel axIndirectMemberLevel= iAxMemberLevelService.selectAxMemberLevelById(sysUserParam.getMemberId());
            Double indirectRate=(Double.valueOf(axIndirectMemberLevel.getIndirectIncomeRate())/100);
            if(indirectRate !=0){
                Double indirectIncome=indirectRate*Double.valueOf(totalFee.toString());
                Double totalIndirectRate= Double.valueOf(sysUserParam.getIndirectIncome()) +(indirectIncome/2);
                sysUserParam.setIndirectIncome(String.format("%.2f",totalIndirectRate));
                sysUserParam.setTotalIncome(String.format("%.2f",Double.valueOf(sysUserParam.getTotalIncome()) +(indirectIncome/2)));
                userService.updateUser(sysUserParam);
                // 增加间接收益明细
                this.adAccountChangeRecord(axOrder,String.format("%.2f",(indirectIncome/2)),sysUserParam.getUserId()  ,String.format("%.2f",indirectIncome),
                        axIndirectMemberLevel.getIndirectIncomeRate(),changeSouceType.推荐.getCode(),changeSouceType.推荐.name());
            }
        }
        /////////////////
        Double  userIncomeRate=   Double.valueOf(axMemberLevel.getIncomeRate())/Double.valueOf("100");
        Double  currentIncome=  Double.valueOf(totalFee.toString()) * userIncomeRate;
        axUser.setTotalIncome(String.format("%.2f", Double.valueOf( axUser.getTotalIncome()) +(currentIncome/2)));
        axUser.setAbleConsumeTotalIncome(String.format("%.2f",(currentIncome/2) + Double.valueOf(axUser.getAbleConsumeTotalIncome())));
        userService.updateUser(axUser);
        //插入委派记录
        axAuthorizationSell.setIncome(String.format("%.2f",currentIncome));
        axAuthorizationSellMapper.insertAxAuthorizationSell(axAuthorizationSell);
        //本金返还记录
            this.adAccountChangeRecord(axOrder,String.format("%.2f",totalFee),axUser.getUserId()  ,"",
               "",changeSouceType.委拍.getCode(),changeSouceType.委拍.name());

       return  this.adAccountChangeRecord(axOrder,String.format("%.2f",(currentIncome/2)),axUser.getUserId()  ,"",
               axMemberLevel.getIncomeRate(),changeSouceType.委拍直接收益.getCode(),changeSouceType.委拍直接收益.name());

        // 增加客户积分明细
//        AxAccountChangeRecord axAccountChangeRecord=new AxAccountChangeRecord();
//        axAccountChangeRecord.setOrderNumber(axAuthorizationSell.getWpOrderNumber());
//        axAccountChangeRecord.setUnitPrice(axAuthorizationSell.getSellPrice()+"");
//        axAccountChangeRecord.setShopNumber(axAuthorizationSell.getSellNumber());
//        axAccountChangeRecord.setGoodId(axOrder.getGoodId());
//        axAccountChangeRecord.setOrderId(axOrder.getId()+"");
//        axAccountChangeRecord.setChangeSource(changeSouceType.委拍.getCode());
//        axAccountChangeRecord.setChangeAmount((String.format("%.2f",totalFee)));
//        axAccountChangeRecord.setSysuserId(sysUserId);
//        axAccountChangeRecord.setChangeSourceName(changeSouceType.委拍.name());
//        return axAccountChangeRecordService.insertAxAccountChangeRecord(axAccountChangeRecord);
    }


    /**
     * 修改订单
     * 
     * @param axOrder 订单
     * @return 结果
     */
    @Override
    public int updateAxOrder(AxOrder axOrder)
    {
        axOrder.setUpdateTime(DateUtils.getNowDate());
        return axOrderMapper.updateAxOrder(axOrder);
    }

    /**
     * 批量删除订单
     * 
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deleteAxOrderByIds(Long[] ids)
    {
        return axOrderMapper.deleteAxOrderByIds(ids);
    }

    /**
     * 删除订单信息
     * 
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deleteAxOrderById(Long id)
    {
        return axOrderMapper.deleteAxOrderById(id);
    }

    @Override
    public AxMySaleInfo selectAxMySaleInfo(AxOrder axOrder) {
        axOrder.setSysUserId(SecurityUtils.getUserId());
        return axOrderMapper.selectAxMySaleInfo(axOrder);
    }

    @Override
    public String getMillseconds(){
        String  secondMills= System.currentTimeMillis()+"";
        secondMills=secondMills.substring(secondMills.length()-4,secondMills.length());
        return secondMills;
    }


    //查询首页销售信息
    public AxIndexSaleInfo selectAxIndexSaleInfo(AxOrder axOrder){
        return axOrderMapper.selectAxIndexSaleInfo(axOrder);
    }

    //近一周的销售数据
    public List<AxIndexSaleInfo>   selectAxIndexSaleInfoByWeek(AxOrder axOrder){
        return axOrderMapper.selectAxIndexSaleInfoByWeek(axOrder);
    }
}
